package com.tech.koufu.ui.adapter;

import java.util.ArrayList;

import com.tech.koufu.model.UserStocks;
import com.tech.koufu.ui.view.GridStocksFragment;
import com.tech.koufu.ui.view.HotStocksFragment;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; 
import android.support.v4.app.FragmentStatePagerAdapter;
import android.util.Log;
import android.view.ViewGroup;

public class StocksGridPagerAdapter extends FragmentStatePagerAdapter {
	private static final String TAG = "StocksGridPagerAdapter";
	private GridStocksFragment gsf1,gsf3;
	HotStocksFragment gsf2;
	public ArrayList<UserStocks> datas;

	public StocksGridPagerAdapter(FragmentManager fm) {
		super(fm); 
	}

	@Override
	public Fragment getItem(int position) { 
		Log.d(TAG, "~~~~getItem~~~~~~~position="+position);
//		return GridStocksFragment.newInstance(position);
		if(position==0){
			if(gsf1!=null){
				return gsf1;
			}else{
				gsf1 = GridStocksFragment.newInstance(position,datas);
			}
			return gsf1;  
		}else if(position==1){
			if(gsf2!=null){
				return gsf2;
			}else{
				gsf2 = HotStocksFragment.newInstance(position);
			}
			return gsf2;  
		}else if(position==2){
			if(gsf3!=null){
				return gsf3;
			}else{
				gsf3 = GridStocksFragment.newInstance(position,null);
			}
			return gsf3;  
		}
		return null;
	}

	@Override
	public int getCount() {
		return 2;
	}

	@Override
	public Object instantiateItem(ViewGroup viewGroup, int position) {
		return super.instantiateItem(viewGroup, position);
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		super.destroyItem(container, position, object);
	}

}
